/*
	Copyright (C) 2011 Daniel C. Dennison (dandennison84@gmail.com).  All rights reserved.
	This file is licensed under the EPL 1.0 (Eclipse Public License 1.0)
	A copy of the license can be found at http://www.eclipse.org/legal/epl-v10.html
*/

package com.gmail.dandennison84.accounting

import org.junit.Before
import org.junit.Test

class RetainedEarningsTest {
	List<Account> coa
	Map<String, List<Account>> incomeStatement
	JournalHelper jh

	@Before
	void before() {
		coa = new ChartOfAccountsHelper().chartOfAccounts
		jh = new JournalHelper()
		incomeStatement = jh.getIncomeStatement(coa)
	}

	@Test
	void testRetainedEarnings() {
		StatementBuilder reb = new StatementBuilder(coa)
		reb.retainedEarnings {
			equityAccounts(accountType:AccountType.EQUITY)
		}

		Map<String, List<Account>> retainedEarningsStatement = reb.accounts

		assert 1 == retainedEarningsStatement.size()
		assert 3 == retainedEarningsStatement['equityAccounts'].size()

		double netIncome = jh.getNetIncome(incomeStatement)
		double equity = jh.getRetainedEarnings(retainedEarningsStatement)
		assert 1000 == equity
		assert 1010 == equity + netIncome
	}
}
